<?php
/**
 +------------------------------------------------------------------------------
 * 控制器展示接口
 +------------------------------------------------------------------------------
 */
abstract class IController
{
	 /**
     +----------------------------------------------------------
     * 初期话函数
     +----------------------------------------------------------
     * @param string $action Action名称
     +----------------------------------------------------------
     * @return object
     +----------------------------------------------------------
     */
	public function dispatch($controller,$action)
    {    	
    	// 初期化
    	$this->preDispatch();
        $this->$action();
        $this->postDispatch();
    }

    /**
     +----------------------------------------------------------
     * 显示表示层函数
     +----------------------------------------------------------
     * @param string $view 表示层名称
     * @param string $data 数据
     +----------------------------------------------------------
     * @return object
     +----------------------------------------------------------
     */
    protected function dialogs($view, $data=array())
    {    	
    	// 调用VIEW
    	extract($data);
        extract($this->data);
        include VIEW_PATH . $view . EXT;
    }
    
    /**
     +----------------------------------------------------------
     * 显示表示层函数
     +----------------------------------------------------------
     * @param string $view 表示层名称
     * @param string $data 数据
     +----------------------------------------------------------
     * @return object
     +----------------------------------------------------------
     */
    protected function view($view,$expand='',$data=array())
    {    	
    	// 调用VIEW
    	extract($data);
        extract($this->data);
        if($expand==""){
        	include VIEW_PATH . 'header/header'.EXT;
	        include VIEW_PATH . $view . EXT;
	        include VIEW_PATH . 'footer/footer'.EXT;
        }else{
	        include VIEW_PATH . 'header/header.'.$expand.EXT;
	        include VIEW_PATH . $view . EXT;
	        include VIEW_PATH . 'footer/footer.'.$expand.EXT;
        }
    }

    /**
     +----------------------------------------------------------
     * 显示表示层函数
     +----------------------------------------------------------
     * @param string $view 表示层名称
     * @param string $data 数据
     +----------------------------------------------------------
     * @return object
     +----------------------------------------------------------
     */
    protected function fetch($view,$expand='',$data=array())
    {
    	// 调用fetch
        ob_start();
        extract($data);
        extract($this->data);
        include VIEW_PATH . 'header/header' . EXT;
        include VIEW_PATH . $view . EXT;
        include VIEW_PATH . 'footer/footer' . EXT;
        return ob_get_clean();
    }
    
    /**
     +----------------------------------------------------------
     * 显示表示层函数
     +----------------------------------------------------------
     * @param string $view 表示层名称
     * @param string $data 数据
     +----------------------------------------------------------
     * @return object
     +----------------------------------------------------------
     */
    protected function cache()
    {
    	$file_path = CACHE_PATH . G('folder') . DIR . G('file') . '.html';
    	if(is_file($file_path))
    	{
    		include $file_path;
    		return true;
    	}
    	return false;        
    }

    /**
     +----------------------------------------------------------
     * 显示表示层函数
     +----------------------------------------------------------
     * @param string $view 表示层名称
     * @param string $data 数据
     +----------------------------------------------------------
     * @return object
     +----------------------------------------------------------
     */
	protected function preDispatch()
    {
    }

    /**
     +----------------------------------------------------------
     * 显示表示层函数
     +----------------------------------------------------------
     * @param string $view 表示层名称
     * @param string $data 数据
     +----------------------------------------------------------
     * @return object
     +----------------------------------------------------------
     */
    protected function postDispatch()
    {
    }
}